import React, { useState, useEffect, useContext, createContext, useReducer, memo, useCallback, useMemo } from 'react'

export default function Test() {
  const [counter, setCounter] = useState(0)
  const [show, setShow] = useState(true)

  const addMemo = useMemo(() => {
    let total = 0
    for (let i = 0; i <= counter; ++i) {
      console.log('for循环被执行了')
      total += i
    }
    return total
  }, [counter])
  return (
    <>
      <div>{counter}</div>
      <div>{addMemo}</div>
      <button onClick={() => setCounter(counter + 1)}>+ 1</button>
      <hr />
      <button onClick={() => setShow(!show)}>切换</button>
    </>
  )
}
